package com.grwx.omc.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.grwx.omc.entity.ResponseData;
import com.grwx.omc.entity.Result;
import com.grwx.omc.admin.entity.SysUser;
import com.grwx.omc.admin.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/user")
public class SysUserController {

    @Resource
    private UserService userService;

    @GetMapping("/get/{id}")
    @ApiOperation("用户管理.根据id查询")
    public SysUser queryUserById(@PathVariable("id") String id) {
        return userService.getById(id);
    }

    @GetMapping("/search/{page}/{size}")
    @ApiOperation("用户管理.分页查询")
    public ResponseData queryUserByPage(@RequestBody(required = false) SysUser sysUser,@PathVariable("page") int page,@PathVariable("size")  int size) {
        Page<SysUser> sysUserPage = new Page<>(page,size);
        IPage<SysUser> result = userService.page(sysUserPage);
        return ResponseData.success(result);
    }

    @PostMapping("/add")
    @ApiOperation("用户管理.新增用户")
    public ResponseData addUser(@RequestBody @Valid SysUser sysUser) {
        boolean save = userService.save(sysUser);
        return ResponseData.success("omc.common.notEmpty");
    }
}
